package com.cs.deviceManager.service.impl;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.cs.deviceManager.domain.DevLocationHistory;
import com.cs.deviceManager.mapper.DevLocationHistoryMapper;
import com.cs.deviceManager.service.IDevLocationHistoryService;

/**
 * 位置变更Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-06-30
 */
@Service
public class DevLocationHistoryServiceImpl implements IDevLocationHistoryService {
    @Autowired
    private DevLocationHistoryMapper devLocationHistoryMapper;

    /**
     * 查询位置变更
     * 
     * @param id 位置变更主键
     * @return 位置变更
     */
    @Override
    public DevLocationHistory selectDevLocationHistoryById(Long id) {
        return devLocationHistoryMapper.selectDevLocationHistoryById(id);
    }

    /**
     * 查询位置变更列表
     * 
     * @param devLocationHistory 位置变更
     * @return 位置变更集合
     */
    @Override
    public List<DevLocationHistory> selectDevLocationHistoryList(DevLocationHistory devLocationHistory) {
        return devLocationHistoryMapper.selectDevLocationHistoryList(devLocationHistory);
    }

    /**
     * 新增位置变更
     * 
     * @param devLocationHistory 位置变更
     * @return 结果
     */
    @Override
    public int insertDevLocationHistory(DevLocationHistory devLocationHistory) {
        return devLocationHistoryMapper.insertDevLocationHistory(devLocationHistory);
    }

    /**
     * 修改位置变更
     * 
     * @param devLocationHistory 位置变更
     * @return 结果
     */
    @Override
    public int updateDevLocationHistory(DevLocationHistory devLocationHistory) {
        return devLocationHistoryMapper.updateDevLocationHistory(devLocationHistory);
    }

    /**
     * 删除位置变更
     * 
     * @param id 位置变更主键
     * @return 结果
     */
    @Override
    public int deleteDevLocationHistoryById(Long id) {
        return devLocationHistoryMapper.deleteDevLocationHistoryById(id);
    }

    /**
     * 批量删除位置变更
     * 
     * @param ids 需要删除的数据主键集合
     * @return 结果
     */
    @Override
    public int deleteDevLocationHistoryByIds(String[] ids) {
        return devLocationHistoryMapper.deleteDevLocationHistoryByIds(ids);
    }

    /**
     * 保存设备位置变更信息
     * 
     * @param devId        设备ID
     * @param oldLatitude  原纬度
     * @param oldLongitude 原经度
     * @param newLatitude  新纬度
     * @param newLongitude 新经度
     * @return 结果
     */
    @Override
    @Transactional
    public int saveLocationChange(Long devId, BigDecimal oldLatitude, BigDecimal oldLongitude, BigDecimal newLatitude,
            BigDecimal newLongitude) {
        DevLocationHistory history = new DevLocationHistory();
        history.setDevId(devId);
        history.setOldLatitude(oldLatitude);
        history.setOldLongitude(oldLongitude);
        history.setNewLatitude(newLatitude);
        history.setNewLongitude(newLongitude);
        history.setChangeTime(new Date());
        return devLocationHistoryMapper.insertDevLocationHistory(history);
    }
}
